﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace DBModel
{

    public partial class WorkAdvertisement
    {
        public override string ToString()
        {
            return WorkTitle;
        }
    }
    public class WorkAdvertisementDB
    {
        [Obsolete("Så här behöver man inte göra kolla GetAllWorkAdvertisement2")]
        public static List<WorkAdvertisement> GetAllWorkAdvertisement()
        {
            var workList = new List<WorkAdvertisement>();
            var query = (from work in DB.Context.WorkAdvertisements
                         select work).ToList();
            workList.AddRange(query.Select(w => new WorkAdvertisement()
            {
                WorkTitle = w.WorkTitle,
                WorkLocation = w.WorkLocation,
                PublishedDate = w.PublishedDate
            }));
            return workList;
                                  
        }

        public static List<WorkAdvertisement> GetAllWorkAdvertisement2()
        {
            return DB.Context.WorkAdvertisements.ToList();

        }

        public static List<WorkAdvertisement> GetWorkAdvertisementsByPublisher(int userId)
        {
            return DB.Context.WorkAdvertisements.Where(w => w.PublisherUserId == userId).ToList();
        }
    }
}
